//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.example.esp8266.activity.utile;

import android.util.Log;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class DataUtils {
    private static String hexStr = "0123456789ABCDEF";
    private static String[] binaryArray = new String[]{"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};

    public DataUtils() {
    }

    public static String getQRContent(String string) {
        string = string.substring(12, string.length() - 1);
        StringBuffer sB = new StringBuffer();
        int num = string.length() / 2;
        char[] chars = new char[num];

        for(int i = 0; i < num; ++i) {
            String temp = string.substring(i * 2, i * 2 + 2);
            int DAscll = Integer.parseInt(temp, 16);
            chars[i] = (char)DAscll;
            sB.append(chars[i]);
        }

        string = sB.toString();
        Log.e("QRCode", string);
        return string;
    }

    public static List<String> hexStr2BinArr(String hexStr, int number) {
        List<String> binaryList = new ArrayList();
        int hexStrLength = hexStr.length();
        StringBuffer sb = new StringBuffer();

        for(int i = 0; i < hexStrLength; ++i) {
            String temp = hexStr.substring(i, i + 1);
            int index = HexToInt(temp);
            sb.append(binaryArray[index]);
        }

        String BinaryString = sb.toString();

        for(int i = 0; i < BinaryString.length(); i += number) {
            binaryList.add(BinaryString.substring(i, i + number));
        }

        return binaryList;
    }

    public static List<String> hexStr2DecimalArr(String hexStr, int number) {
        List<String> decimalList = new ArrayList();
        int hexStrLength = hexStr.length();
        new StringBuffer();

        for(int i = 0; i < hexStrLength; i += number) {
            String hex = hexStr.substring(i, i + number);
            String decimal = String.valueOf(HexToInt(hex));
            decimalList.add(decimal);
        }

        return decimalList;
    }

    public static String demToHex(int i) {
        StringBuffer Hex = new StringBuffer("");
        String m = "0123456789abcdef";
        if (i == 0) {
            Hex.append(i);
        }

        while(i != 0) {
            Hex.append(m.charAt(i % 16));
            i >>= 4;
        }

        return Hex.reverse().toString();
    }

    public static int HexToInt(String inHex) {
        return Integer.parseInt(inHex, 16);
    }

    public static int HexToBinary(String Hex) {
        return Integer.parseInt(Hex, 2);
    }

    public static int isOdd(int num) {
        return num & 1;
    }

    public static String IntToHex(int intHex) {
        return Integer.toHexString(intHex);
    }

    public static byte HexToByte(String inHex) {
        return (byte)Integer.parseInt(inHex, 16);
    }

    public static String Byte2Hex(Byte inByte) {
        return String.format("%02x", inByte).toUpperCase();
    }

    public static String ByteArrToHex(byte[] inBytArr) {
        StringBuilder strBuilder = new StringBuilder();
        byte[] var2 = inBytArr;
        int var3 = inBytArr.length;

        for(int var4 = 0; var4 < var3; ++var4) {
            byte valueOf = var2[var4];
            strBuilder.append(Byte2Hex(valueOf));
            strBuilder.append(" ");
        }

        return strBuilder.toString();
    }

    public static String ByteArrToHex(byte[] inBytArr, int offset, int byteCount) {
        StringBuilder strBuilder = new StringBuilder();
        int j = byteCount;

        for(int i = offset; i < j; ++i) {
            strBuilder.append(Byte2Hex(inBytArr[i]));
        }

        return strBuilder.toString();
    }

    public static byte[] HexToByteArr(String inHex) {
        int hexlen = inHex.length();
        byte[] result;
        if (isOdd(hexlen) == 1) {
            ++hexlen;
            result = new byte[hexlen / 2];
            inHex = "0" + inHex;
        } else {
            result = new byte[hexlen / 2];
        }

        int j = 0;

        for(int i = 0; i < hexlen; i += 2) {
            result[j] = HexToByte(inHex.substring(i, i + 2));
            ++j;
        }

        return result;
    }

    public static List<String> getDivLines(String inputString, int length) {
        List<String> divList = new ArrayList();
        int remainder = inputString.length() % length;
        int number = (int)Math.floor((double)(inputString.length() / length));

        for(int index = 0; index < number; ++index) {
            String childStr = inputString.substring(index * length, (index + 1) * length);
            divList.add(childStr);
        }

        if (remainder > 0) {
            String cStr = inputString.substring(number * length, inputString.length());
            divList.add(cStr);
        }

        return divList;
    }

    public static String twoByte(String val) {
        if (val.length() > 4) {
            val = val.substring(0, 4);
        } else {
            int l = 4 - val.length();

            for(int i = 0; i < l; ++i) {
                val = "0" + val;
            }
        }

        return val;
    }

    public static String sum(String cmd) {
        List<String> cmdList = getDivLines(cmd, 2);
        int sumInt = 0;

        String c;
        for(Iterator var3 = cmdList.iterator(); var3.hasNext(); sumInt += HexToInt(c)) {
            c = (String)var3.next();
        }

        String sum = IntToHex(sumInt);
        sum = twoByte(sum);
        cmd = cmd + sum;
        return cmd.toUpperCase();
    }
}
